#!/usr/bin/python

import os

cmd_dict={
'make_plot_SF_incl_ZM.py':'MZ',
'make_plot_SF_ch_ZM.py':'MZ',
'make_plot_SF_incl_ZPt.py':'PtZ',
'make_plot_SF_ch_ZPt.py':'PtZ',
'make_plot_SF_incl_ZEta.py':'EtaZ',
'make_plot_SF_Nvtx.py':'Nvtx',
'make_plot_SF_incl_LepPt.py':'LepPt',
'make_plot_SF_LepEtaPhi.py':'LepEtaPhi',
'make_plot_SF_rebin_Eta.py':'LepEtaPhi',
'make_plot_SF_type.py':'LepType',
'test_bkgTemp_mzz.py':'BkgTemp',
'test_bkgTemp_zzpt.py':'BkgTemp'
}


plots_dir="Plots_Ratio"

file='test.py'
for file in cmd_dict.keys():
    print "INFO => running %s" % file
    cmd="sed s/'RatioSize=-0.2'/'RatioSize=0.2'/g "+file+ ">" +file+".temp"
    os.system(cmd)
    cmd="mv "+file+".temp"+" "+file
    os.system(cmd)
    cmd='''sed s/"ATLAS=''"/"ATLAS='ALTAS Preliminary'"/g '''+file+ ">" +file+".temp"
    os.system(cmd)
    cmd="mv "+file+".temp"+" "+file
    os.system(cmd)
    cmd="python "+file + " -b > out"
    os.system(cmd)
    if not os.path.isdir(cmd_dict[file]): os.mkdir(cmd_dict[file])
    cmd="mv *.png *.pdf *.eps *.root " + cmd_dict[file]+"/"
    os.system(cmd)

if not os.path.isdir(plots_dir): os.mkdir(plots_dir)
else:
    cmd="rm "+plots_dir+"/*"+" -rf"
    os.system(cmd)
for file in cmd_dict.keys():
    if os.path.isdir(cmd_dict[file]):
        cmd="mv "+cmd_dict[file]+"/"+" "+plots_dir+"/"
        os.system(cmd)

